﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 用户管理系统 {

    //Controller响应数据统一格式
    //Code返回0表示正常
    public interface RI {
        public int Code { set; get; }
        public string Msg { set; get; }
    }
    public struct R<T> :RI{
        public T? Data { set; get; }
        public int Code { set; get; }
        public string Msg { set; get; }

        public readonly bool IsFail() => Code != 0;

        public static R<T> Ok() => R<T>.Get(0, "OK");

        public static R<T> Ok(T data) => R<T>.Get(0, "OK", data);
        internal static R<T> Error(string msg) => R<T>.Get(-1, msg);

        private static R<T> Get(int code, string msg) => new() { Code = code, Msg = msg };
        private static R<T> Get(int code, string msg, T data) => new() { Code = code, Msg = msg, Data = data };


    }

    public class User {
        private Industry[]? _industrys;
        public string? No { set; get; }
        public string? Name { set; get; }
        public Gender? Gender { set; get; }

        public Industry[] Industrys {
            set => _industrys = value ?? [Industry.未知];
            get => _industrys ?? [Industry.未知];
        }

    }
    public enum Gender {
        未知 = 0,
        男 = 1,
        女 = 2,
    }
    public enum Industry {
        未知 = 0,
        政府 = 1,
        企业 = 2,
        教育 = 3,
        其他 = 4
    }
}
